package rrLevel;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class ExpManager implements Listener {
	public JavaPlugin parent;
	public static int perLevelMultiplayExp;
	public static int baseLevelExp;
	
	public ExpManager(JavaPlugin parent_) {
		parent = parent_;
		perLevelMultiplayExp = parent_.getConfig().getInt(
				"Level.PerLevelMultiplay");
		baseLevelExp = parent_.getConfig().getInt("Level.BaseLevelExp");
	}

	@EventHandler
	void onEntityDamage(EntityDamageByEntityEvent event) {

	}

	public int lvl2exp(int lvl) {
		return lvl * perLevelMultiplayExp * baseLevelExp;
	}

	public int exp2lvl(int exp) {
		int level = 0;
		for (level = 0;; level++)
			if ((level + 1) * perLevelMultiplayExp * baseLevelExp > exp)
				return level;
	}

	public int getPlayerLevel(String playerName) {
		return exp2lvl(getPlayerExp(playerName));
	}

	public int getPlayerLevel(Player player) {
		return getPlayerLevel(player.getName());
	}

	// return true if level up
	public boolean addPlayerExp(String playerName, int exp) {
		return true;
	}

	public boolean addPlayerExp(Player player, int exp) {
		return addPlayerExp(player.getName(), exp);
	}

	public int getPlayerExp(String playerName) {
		return 0;
	}

	public int getPlayerExp(Player player) {
		return getPlayerExp(player.getName());
	}
}
